package com.example.security.common;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * 分页结果
 */
@Data
@Accessors(chain = true)
public class PageResult<T> {
    /**
     * 总记录数
     */
    private long total;

    /**
     * 当前页数据
     */
    private List<T> list;

    /**
     * 总页数
     */
    private long pages;

    /**
     * 当前页
     */
    private int pageNum;

    /**
     * 每页记录数
     */
    private int pageSize;

    public PageResult() {
    }

    public PageResult(List<T> list, long total) {
        this.list = list;
        this.total = total;
        this.pageNum = 1;
        this.pageSize = list.size();
        this.pages = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
    }

    public PageResult(List<T> list, long total, int pageNum, int pageSize) {
        this.list = list;
        this.total = total;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.pages = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
    }

    public static <T> PageResult<T> of(List<T> list, long total) {
        return new PageResult<>(list, total);
    }

    public static <T> PageResult<T> of(List<T> list, long total, int pageNum, int pageSize) {
        return new PageResult<>(list, total, pageNum, pageSize);
    }
} 